/**
 * Created by guosc on 2016/11/4 0004.
 */
define([
    'require',
    'angular',
    'underscore'
], function (require, angular, _) {
    return  function ($scope, Resource,GillionMsg,$rootScope,RuleSerivce) {
        angular.element('.engine-tab li:first').trigger('click');
        RuleSerivce.promises().then(function () {
            $scope.ruleId=$rootScope.currRule.id;
            rule.get({
                id:$scope.ruleId
            }, function (resp) {
                $scope.rule=resp;
            });
        });


        var rule=Resource("/grule-manager/rule/:id",{
            id:"@id"
        });



        $scope.reset=function(){
            $scope.rule=rule.get({
                id:$scope.ruleId
            });
        }

        $scope.save=function(){
            angular.element('form[name="RuleForm"]').scope().RuleForm.verify().then(function(){
                rule.update($scope.rule,function(resp){
                    if(resp.success){
                        GillionMsg.alert("提示","保存成功！");
                        RuleSerivce.setCurrentRule($scope.rule);
                        angular.element(document).trigger('refresh.menu');
                    }
                })
            });
        };
    }
})


